<?php
function locateBin($bin) {
    foreach (array('/usr/local/bin','/usr/bin','/bin','/usr/sbin') as $dir) {
        if (file_exists($dir.'/'.$bin)) {
            return $dir.'/'.$bin;
        }
    }
    return $bin;
}
error_reporting(E_ALL ^ E_NOTICE);
if ($_SERVER['argc']<3) {
    echo 'php ',$_SERVER['argv'][0],' LocalSettings.php text.sql',"\n";
    die();
}
$f = $_SERVER['argv'][1];
if (!file_exists($f)) {
    echo 'file ',$f," not exists\n";
    die();
}

$sql_file = $_SERVER['argv'][2];
if (!file_exists($sql_file)) {
    echo 'file ',$sql_file," not exists\n";
    die();
}
define('MEDIAWIKI',1);
require_once($f);
system(locateBin('mysql').' -h'.$wgDBserver.' -u'.$wgDBuser.' -p'.$wgDBpassword.' '.' --database '.$wgDBname.' -A <'.$sql_file);
